using System.Data;
using System.Web;
using ACM.cmsarea08.Administration;


namespace ACM.cmsarea08.Administration.Core.Layout {
	
	public class Funzioni {
		private static Funzioni _instance;
		private static object locker=new object();
		public static Funzioni LayoutHandler {
			get {
				if(_instance==null) {
					lock(locker) {
						_instance = new Funzioni();
					}
				}
				return _instance;
			}
			set {
				_instance = value;
			}
		}
		private Funzioni() {
			dclass = new Administration.Core.DBClass();
		}
		
		
		
		private Administration.Core.DBClass dclass;
		
		public DataSet getAdminMenu(string lingua) {
			if(HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua] == null) {
				HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua] = 
					ACM.cmsarea08.Administration.Core.AdminMenuGenerator.adminMenu.getBaseMenu(lingua);
			}
			return (DataSet)HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua];
		}
		public DataSet getAdminMenu(string lingua,string[] roles) {
			if(HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua] == null) {
				// comprimi i ruoli:
				HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua] = 
					ACM.cmsarea08.Administration.Core.AdminMenuGenerator.adminMenu.getBaseMenu(lingua,roles);
			}
			return (DataSet)HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua];
		}		

		public DataSet GetCustomAdminMenu(string[] roles,string lingua) {
			if(HttpContext.Current.Session["adm_CCLayoutGAdminMenu_"+lingua] == null) {
				// comprimi i ruoli:
				HttpContext.Current.Session["adm_CCLayoutGAdminMenu_"+lingua] = 
					ACM.cmsarea08.Administration.Core.AdminMenuGenerator.adminMenu.getCustomMenu(lingua,roles);
					//dclass.GetCustomAdminMenu(lingua,roles);
			}
			return (DataSet)HttpContext.Current.Session["adm_CCLayoutGAdminMenu_"+lingua];
		}		
		
		
		public DataSet ApplyCustomMenu(DataSet customMenu,string lingua) {
			DataSet baseMenu = null;
			if(HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua] == null)
				return null;
			else
				baseMenu = (DataSet) HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua];

			DataSet ds = ACM.cmsarea08.Administration.Core.AdminMenuGenerator.adminMenu.ApplyCustomMenu(baseMenu,customMenu,lingua);
			HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua] = ds;
			return ds;
		}
		
		public void clearAdminMenu(string lingua) {
			HttpContext.Current.Session.Remove("adm_LayoutGAdminMenu_" + lingua);
		}
		public void UpdateAdminMenu(string lingua) {
			if(HttpContext.Current.Session["adm_LayoutGAdminMenu_"+lingua] != null) {
				HttpContext.Current.Session.Remove("adm_LayoutGAdminMenu_"+lingua);
			}
		}
		
		
	}

	
}
namespace ACM.cmsarea08.Administration.Core {
	public enum TipiPagineLista {
		BlocchiVisivi,
		Menu,
		Contenuti,
		Moduli,
		ModuliInstall
	}	
}
